/*
	NounField.h

	A field is a collidable root object, that cannot be detected usually. It's position is linked to another noun, possibly a child of
	another object (i.e. GadgetJD on a ship)

	(c)2004 Palestar Inc, Richard Lyle
*/

#ifndef NOUNFIELD_H
#define NOUNFIELD_H

#include "NounGame.h"

//----------------------------------------------------------------------------

class NounField : public NounGame
{
public:
	DECLARE_WIDGET_CLASS();
	DECLARE_PROPERTY_LIST();

	// Types
	typedef Reference< NounField >				Ref;
	typedef WidgetReference< NounField >		wRef;

	// Construction
	NounField();

	// Widget interface
	bool			read( InStream & input );
	// BaseNode interface
	float			radius() const;					// radius for this object

	// Noun interface
	NounType		nounType() const;
	bool			collidable() const;				// can this object collide
	bool			canBeDetected() const;			// can this object be detected
	
	void			initialize();
	void			release();
	void			simulate( dword nTick );	

	void			collision( Noun * pCollide,
						const Vector3 & intersect );	// handle collision between two colliable objects, intersect position is in world space

	// Accessors
	Noun *			link() const;					// get the object link

	// Mutators
	void			setLink( Noun * pNoun );		// link this field to the position of another object
	void			setFieldRadius( float fRadius );
	
	virtual void	onEnterField( Noun * pNoun ) = 0;
	virtual void	onInsideField( Noun * pNoun ) = 0;
	virtual void	onLeaveField( Noun * pNoun ) = 0;

protected:
	// Data
	Noun::wRef		m_pLink;
	float			m_fFieldRadius;

	HashArray< WidgetKey, Noun::wRef >
					m_InField;

	// non-serialized
	dword			m_nUpdateField;
};

//----------------------------------------------------------------------------

inline float NounField::radius() const
{
	return m_fFieldRadius;
}

inline Noun * NounField::link() const
{
	return m_pLink;
}

//----------------------------------------------------------------------------



#endif

//----------------------------------------------------------------------------
//EOF
